#coding=utf-8
#多进程共享变量爬虫
import multiprocessing
from img_tool import *

def start(noteCount,noteIndex,path,param):
    while noteIndex.value<noteCount:
       noteAddr="http://jfbra.com/web_page/forum_h5/post.html?post_id="
       url="http://app.jfbra.com/bra_app/post/get_share_post/"
       noteAddr=noteAddr+str(noteIndex.value)
       url=url+str(noteIndex.value)
       print noteAddr
       noteIndex.value=noteIndex.value+1
       response = urllib.urlopen(url).read()
       try:
        get_detail(response,path,param,noteAddr)
       except:
        continue

if __name__ == "__main__":
    startIndex=10000
    noteIndex = multiprocessing.Value('i', startIndex) #帖子索引
    noteCount=40000 #帖子条数
    processList=[] #进程列表
    processCount=10 #进程数
    dir=u"D://temp/"+str(time.time())+"/"
    make_dir(dir)
    param=[2000,20,20]#浏览数，评论数，点赞
    for i in range(processCount):
        p = multiprocessing.Process(target=start,args=(noteCount,noteIndex,dir,param))
        processList.append(p)
    for p in processList:
        p.start()
    for p in processList:
        p.join()